﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CascadeDropDown.Library.Component;

namespace CascadeDropDown.Data
{
    public class AddressViewModel : ViewModelBase<AddressViewModel>
    {
        //Default olarak ViewModel'in property'leri Get edilebilir mi (CanGet)
        protected override bool DefaultAccess { get { return true; } }
        
        //Model üzerindeki propertyler
        public int? IlID { get; set; }
        public int? IlceID { get; set; }
        public int? SemtID { get; set; }

        protected AddressService addressDataService = new AddressService();

        //UI Logic ya da UI Bussiness
        protected override void PrepareBussiness()
        {
            this.CreateAccessRule("IlceID", AllowFor.Get | AllowFor.Set, () => this.IlID.HasValue);
            this.CreateAccessRule("SemtID", AllowFor.Get | AllowFor.Set, () => this.IlceID.HasValue);

            this.AddDatasource("IlID", () => this.addressDataService.IlData());
            this.AddDatasource("IlceID", () => this.addressDataService.IlceData(this.IlID.Value));
            this.AddDatasource("SemtID", () => this.addressDataService.SemtData(this.IlID.Value, this.IlceID.Value));
        }
    }
}
